package gmu.swe.project.utils;

import java.util.Calendar;
import java.util.Date;

import gmu.swe.project.io.ConfigFileParser;

/**
 * A collection of helper methods that are needed by different classes in the
 * project.
 * 
 * @author Stacy Meyer
 *
 */
public class Helper {

	/**
	 * Get the parser to read through the configuration file, config.xml
	 * @return ConfigFileParser parser to traverse config.xml
	 */
	public static ConfigFileParser getParser() {
		String location = System.getProperty("CONFIG_FILE_LOCATION", "C:\\Temp\\config.xml");
		System.out.println("Helper::getParser():location: " + location);
		ConfigFileParser parser = new ConfigFileParser(location);
		return parser;
	}//getParser
	
	/**
	 * Get the current time
	 * 
	 * @return Date current time
	 */
	public static Date getCurrTime() {
		Calendar cal = Calendar.getInstance();
		return cal.getTime();
	}// getCurrTime
	
	/**
	 * Compare the current time with each tracker's time
	 * 
	 * @param currTime
	 * @param trackerTime
	 * @return
	 */
	public static long compareTime(long currTime, long pingTime) {
		// right now we are comparing in seconds, divide by 60 if you want to
		// compare in minutes
		long timeDiff = (Math.abs((currTime - pingTime) / 1000));
		System.out.println("Helper::compareTime():timeDiff: "
				+ Long.toString(timeDiff));
		return timeDiff;
	}// compareTime
	
}//class Helper(...
